#encoding:utf-8 
import os.path, sys, os#, gzip


def compress_file(fn_in, fn_out):  
    f_in = open(fn_in, 'rb')  
    f_out = gzip.open(fn_out, 'wb')  
    f_out.writelines(f_in)  
    f_out.close()  
    f_in.close() 


def zip_dir(dirname,zipfilename):
    """
    | ##@函数目的: 压缩指定目录为zip文件
    | ##@参数说明：dirname为指定的目录，zipfilename为压缩后的zip文件路径
    | ##@返回值：无
    | ##@函数逻辑：
    """
    import zipfile
    # print("dirname ="+dirname)
    # print("zipfilename ="+zipfilename)

    filelist = []
    if os.path.isfile(dirname):
        filelist.append(dirname)
    else :
        for root, dirs, files in os.walk(dirname):
            for name in files:
                if name.endswith(".lua"):
                    filelist.append(os.path.join(root, name))
 
    zf = zipfile.ZipFile(zipfilename, "w", zipfile.zlib.DEFLATED)
    for tar in filelist:
        arcname = tar[len(dirname):]
        # print("arcname ="+arcname)
        #print arcname
        zf.write(tar,arcname)
    zf.close()




def zip_lpkg(frompath,tarfile):
	index = tarfile.rindex('.')
	zip_dir(frompath, tarfile)